'use strict';
const { AuthFailed } = require('@utils/http-exception');

module.exports = () => {
  return async (ctx, next) => {
    const user = await ctx.service.users.getUser(ctx.username);
    if (!user) {
      throw new AuthFailed();
    } else {
      await next();
    }
  };
};
